$(document).ready(function(){
            themeprimary = getThemeColorFromCss('themeprimary');
            themesecondary = getThemeColorFromCss('themesecondary');
            themethirdcolor = getThemeColorFromCss('themethirdcolor');
            themefourthcolor = getThemeColorFromCss('themefourthcolor');
            themefifthcolor = getThemeColorFromCss('themefifthcolor');

            

            var data = [],
            totalPoints = 300;

        function getRandomData() {

            if (data.length > 0)
                data = data.slice(1);

            // Do a random walk

            while (data.length < totalPoints) {

                var prev = data.length > 0 ? data[data.length - 1] : 50,
                    y = prev + Math.random() * 10 - 5;

                if (y < 0) {
                    y = 0;
                } else if (y > 100) {
                    y = 100;
                }

                data.push(y);
            }

            // Zip the generated y values with the x values

            var res = [];
            for (var i = 0; i < data.length; ++i) {
                res.push([i, data[i]]);
            }

            return res;
        }
        // Set up the control widget
        var updateInterval = 60000;
        var plot = $.plot("#realtime-chart", [getRandomData()], {
        	 xaxis: {
                 color: '#f3f3f3',
                 tickFormatter: function (val, axis) {
                     return val;
                 }
             },
             yaxis: {
                color: '#f3f3f3',
                tickFormatter: function (val, axis) {
                    return val;
                }
            },
            colors: [themeprimary],
            tooltip: true,
            tooltipOpts: {
                defaultTheme: false,
                content: " <b>%x </b> , <b>%s</b> : <span>%y</span>",
            },
            grid: {
                hoverable: true,
                clickable: false,
                borderWidth: 0,
                aboveData: false
            }
        });

        function update() {
            plot.setData([getRandomData()]);
            plot.draw();
            setTimeout(update, updateInterval);
        }
        update();
});
$(document).ready(function(){
		//InitiateEasyPieChart.init();
         //报告
         Report.init();
         //疾病
         CaseChartJS.init();
         //任务
         TaskChartJS.init();
         //用户
         DoctorAndUser.init();
         //拆分预约单
         CFChart.init();
});
var Report = function(){
	return {
		init:function(){
			
			var myDate = new Date();
			$.ajax({
				type:"post",
				url:ctx+"/console/loadReport",
				dataType:"json",
				success:function(data){
					
					var strReport = data["strReport"];
					var strExamination = data["strExamination"];
					var strAssessment = data["strAssessment"];
					
					var report = echarts.init(document.getElementById('report'));
					option = {
						    tooltip: {
						        trigger: 'axis'
						    },
						    legend: {
						        data:['问卷调查','体检报告','健康评估']
						    },
						    grid: {
						        left: '3%',
						        right: '4%',
						        bottom: '3%',
						        containLabel: true
						    },
						    toolbox: {
						    	show: true,
						        feature: {
						            magicType: {type: ['line', 'bar', 'stack', 'tiled']},
						            saveAsImage: {}
						        }
						    },
						    xAxis: {
						        type: 'category',
						        boundaryGap: false,
						        data: [dateStr(-6),dateStr(-5),dateStr(-4),dateStr(-3),dateStr(-2),dateStr(-1),dateStr(0)]
						    },
						    yAxis: {
						        type: 'value'
						    },
						    series: [
						        {
						            name:'问卷调查',
						            type:'line',
						            stack: '总量',
						            data:strReport
						        },
						        {
						            name:'体检报告',
						            type:'line',
						            stack: '总量',
						            data:strExamination
						        },
						        {
						            name:'健康评估',
						            type:'line',
						            stack: '总量',
						            data:strAssessment
						        }
						    ]
						};
					report.setOption(option);
				}
			});
			
		}
	}
}();
//用户医师
 var DoctorAndUser = function (){
	 return {
		 init: function(){
				$.ajax({
					type:"post",
					url:ctx+"/console/loadDoctorAndUser",
					dataType:"json",
					success:function(data){
						var myChart = echarts.init(document.getElementById('doctorAndUser'));
						 
						 var option = {
								    tooltip: {
								        trigger: 'item',
								        formatter: "{a} <br/>{b}: {c} ({d}%)"
								    },
								    toolbox: {
								        feature: {
								            saveAsImage: {}
								        }
								    },
								    legend: {
								        orient: 'vertical',
								        x: 'left',
								        data:['会员线下','会员APP','医师线下','医师APP']
								    },
								    series: [
								        {
								            name:'来源',
								            type:'pie',
								            selectedMode: 'single',
								            radius: ['0', '75%'],

								            label: {
								                normal: {
								                    position: 'inner'
								                }
								            },
								            labelLine: {
								                normal: {
								                    show: false
								                }
								            },
								            data:data
								        }
								    ]
								};
						 myChart.setOption(option);
					}
				});
			 
			 
		 }
	 }
 }();
//任务
 var TaskChartJS = function () {
	    return {
	        init: function () {
	        	var placeholder = echarts.init(document.getElementById('historyTask'));
	        	option = {
	        		    tooltip: {
	        		        trigger: 'item',
	        		        formatter: "{a} <br/>{b}: {c} ({d}%)"
	        		    },
					    toolbox: {
					        feature: {
					            saveAsImage: {}
					        }
					    },
	        		    legend: {
	        		        data:['已执行','未执行','执行失败']
	        		    },
	        		    series: [
	        		        {
	        		            name:'来源',
	        		            type:'pie',
	        		            radius: ['40%', '55%'],
	        		            color:["#a0d468","#ffce55","#ed4e2a"],
	        		            data:[
	        		                {value:335, name:'已执行'},
	        		                {value:310, name:'未执行'},
	        		                {value:234, name:'执行失败'}
	        		            ]
	        		        }
	        		    ]
	        		};
	        	placeholder.setOption(option);
	        }
	    };
	}();
 //病例详情
 var CaseChartJS = function () {
     return {
         init: function () {
        	 var placeholder = echarts.init(document.getElementById('pie-chart'));
        	 option = {
        			    tooltip : {
        			        trigger: 'axis',
        			        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
        			            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        			        }
        			    },
    				    toolbox: {
    				    	show: true,
    				        feature: {
    				            magicType: {type: ['line', 'bar', 'stack', 'tiled']},
    				            saveAsImage: {}
    				        }
    				    },
        			    legend: {
        			        data: ['男', '女','北方','南方']
        			    },
        			    grid: {
        			        left: '3%',
        			        right: '4%',
        			        bottom: '3%',
        			        containLabel: true
        			    },
        			    xAxis:  {
        			        type: 'value'
        			    },
        			    yAxis: {
        			        type: 'category',
        			        data: ['高血压','糖尿病','脑卒中','乳腺癌']
        			    },
        			    series: [
        			        {
        			            name: '男',
        			            type: 'bar',
        			            stack: '总量',
        			            label: {
        			                normal: {
        			                    show: true,
        			                    position: 'insideRight'
        			                }
        			            },
        			            data: [334, 390, 330, 320]
        			        },
        			        {
        			            name: '女',
        			            type: 'bar',
        			            stack: '总量',
        			            label: {
        			                normal: {
        			                    show: true,
        			                    position: 'insideRight'
        			                }
        			            },
        			            data: [134, 90, 230, 210]
        			        },
        			        {
        			            name: '北方',
        			            type: 'bar',
        			            stack: '总量',
        			            label: {
        			                normal: {
        			                    show: true,
        			                    position: 'insideRight'
        			                }
        			            },
        			            data: [ 234, 290, 330, 310]
        			        },
        			        {
        			            name: '南方',
        			            type: 'bar',
        			            stack: '总量',
        			            label: {
        			                normal: {
        			                    show: true,
        			                    position: 'insideRight'
        			                }
        			            },
        			            data: [154, 190, 330, 410]
        			        }
        			    ]
        			};
        	 placeholder.setOption(option);
         }
     };
 }();
 
 var CFChart = function () {
	    return {
	        init: function () {
	        	var placeholder = echarts.init(document.getElementById('cfchart'));
	        	option = {
					    tooltip: {
					        trigger: 'axis'
					    },
	        		    legend: {
	        		    	orient: 'vertical',
					        x: 'left',
	        		        data:['女','男']
	        		    },
	        		    toolbox: {
	        		        show: true,
	        		        feature: {
	        		            magicType: {type: ['line', 'bar']},
	        		            saveAsImage: {}
	        		        }
	        		    },
	        		    xAxis:  {
	        		        type: 'category',
	        		        boundaryGap: false,
	        		        data: ['周一','周二','周三','周四','周五','周六','周日']
	        		    },
	        		    yAxis: {
	        		        type: 'value'
	        		    },
	        		    series: [
	        		        {
	        		            name:'女',
	        		            type:'line',
	        		            data:[11, 11, 15, 13, 12, 13, 10],
	        		            markPoint: {
	        		                data: [
	        		                    {type: 'max', name: '最大值'},
	        		                    {type: 'min', name: '最小值'}
	        		                ]
	        		            }
	        		        },
	        		        {
	        		            name:'男',
	        		            type:'line',
	        		            data:[1, 3, 2, 5, 3, 2, 0],
	        		            markPoint: {
	        		                data: [
	        		                    {name: '周最低', value: -2, xAxis: 1, yAxis: -1.5}
	        		                ]
	        		            }
	        		        }
	        		    ]
	        		};
	        	placeholder.setOption(option);
	        }
	    };
	}();
	function dateStr(val) {
        var dd = new Date();
        dd.setDate(dd.getDate()+val);
        var y = dd.getFullYear();
        var m = dd.getMonth()+1;
        var d = dd.getDate();
        return y+"-"+m+"-"+d;
    }
